package com.gupao.p7store.common.holder;


import com.gupao.p7store.common.aware.AwareApplicationProperty;
import com.gupao.p7store.common.aware.AwareSpringContext;
import org.apache.commons.lang3.StringUtils;


/**
 * desc: 属性持有者
 *
 * @ClassName: com.gupao.p7store.common.holder.PropertyHolder
 * @Author: dengbicheng
 * @CreateTime: 2022-02-08 16:41:33
 * @Version: v 1.0.0
 */
public class PropertyHolder {

    private static AwareApplicationProperty holder = AwareSpringContext.getBean(AwareApplicationProperty.class);

    /**
     * 窥视值
     *
     * @param key 键名
     * @return {@link String}
     */
    public static String peek(String key) {
        if(null == holder){
            return null;
        }
        return holder.getPropertiesValue(key);
    }

    /**
     * 窥视值
     *
     * @param key 键名
     * @param def def
     * @return {@link String}
     */
    public static String peek(String key, String def) {
        String value = peek(key);
        return StringUtils.isEmpty(value) ? def : value;
    }

    /**
     * 窥视值
     *
     * @param key 键名
     * @param def def
     * @return {@link String}
     */
    public static Integer peek(String key, Integer def) {
        String value = peek(key);
        return StringUtils.isEmpty(value) ? def : Integer.parseInt(value);
    }

}
